package com.tanhua.service;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanhua.api.UserApi;
import com.tanhua.mapper.UserMapper;
import com.tanhua.model.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserApi {


    @Autowired
    private UserMapper userMapper;

    @Override
    public User byMobileUser(String mobile) {

        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
        userWrapper.eq(User::getMobile,mobile);
        User user = userMapper.selectOne(userWrapper);

        return user;
    }

    @Override
    public Long saveUser(User user) {

        userMapper.insert(user);

        User user1 = this.byMobileUser(user.getMobile());

        return Long.valueOf(user1.getId());
    }
}
